using System.Text.Json.Serialization;
using System.Collections.Generic;

namespace Sage.Http.Options
{
    /// <summary>
    /// 重试策略配置选项
    /// </summary>
    public class RetryOptions
    {
        /// <summary>
        /// 是否启用重试
        /// </summary>
        [JsonPropertyName("Enabled")]
        public bool Enabled { get; set; } = false;

        /// <summary>
        /// 最大重试次数
        /// </summary>
        [JsonPropertyName("MaxRetryCount")]
        public int MaxRetryCount { get; set; } = 3;

        /// <summary>
        /// 初始延迟（毫秒）
        /// </summary>
        [JsonPropertyName("InitialDelayMs")]
        public int InitialDelayMs { get; set; } = 1000;

        /// <summary>
        /// 退避乘数
        /// </summary>
        [JsonPropertyName("BackoffMultiplier")]
        public double BackoffMultiplier { get; set; } = 2.0;

        /// <summary>
        /// 最大延迟（毫秒）
        /// </summary>
        [JsonPropertyName("MaxDelayMs")]
        public int MaxDelayMs { get; set; } = 30000;

        /// <summary>
        /// 需要重试的状态码
        /// </summary>
        [JsonPropertyName("RetryStatusCodes")]
        public List<int> RetryStatusCodes { get; set; } = new List<int> { 408, 429, 500, 502, 503, 504 };
        
        /// <summary>
        /// 创建当前选项的副本
        /// </summary>
        public RetryOptions Clone()
        {
            return new RetryOptions
            {
                Enabled = this.Enabled,
                MaxRetryCount = this.MaxRetryCount,
                InitialDelayMs = this.InitialDelayMs,
                BackoffMultiplier = this.BackoffMultiplier,
                MaxDelayMs = this.MaxDelayMs,
                RetryStatusCodes = new List<int>(this.RetryStatusCodes)
            };
        }
    }
}